#!/usr/bin/env python
#
#       Logic.py
#       
#       Copyright 2010 Propellor and Ratchet Games http://pandrgames.co.uk/
#       


class Logic:
    def __init__(self, gametype=0):
        self.gametype = gametype
        
        #KINGOFTHEHILL
        #1Ki, 4P
        #5P
        #Win: kill 1Ki or 5P
        
        #CHESS
        #1Ki, 1Q, 2Kn, 2B, 2R, 8P
        #Win: kill 1Ki
        
        
        
        
    def shipded(self, playerlist, player, ship):
        if self.gametype == 0:
            pass
        elif self.gametype == "KINGOFTHEHILL":
            if playerlist[player].ships[ship].type == "King":
                #player in playerlist who isn't player, wins
                newlist = []
                for guy in playerlist:
                    if guy.key() != player:
                        newlist.append(guy.key)
                awin(newlist)
                
            elif len(playerlist[player].ships) == 0:
                newlist = []
                for guy in playerlist:
                    if guy.key() != player:
                        newlist.append(guy.key)
                awin(newlist)
                
            

    def shipdamaged(self, playerlist, p1, ship1, p2, ship2, damage):
        #when ship1 damages ship2
        print "=L=: ",p1,"[",ship1,"] did",damage,"damage to",p2,"[",ship2,"]."
        if self.gametype == 0:
            pass
        
    
    
    
    def awin(self, playerlist):
        #list of keys of players who won, all others don't.
        print "=L=: Players",
        for player in playerlist:
            print player,
        print "WIN!"